package com.itheima.controller.user;

import com.itheima.common.entity.Result;
import com.itheima.common.utils.ValidateCodeUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

@RestController
@Slf4j
@RequestMapping("/validatecode")
public class ValidatecodeController {
    @Autowired
    private RedisTemplate redisTemplate;
    @PostMapping("/send4Order")
    public Result send4Order(int telephone) {
        log.info("手机号：{}", telephone);
        String code4String = ValidateCodeUtils.generateValidateCode4String(telephone);
        // 将验证码保存到redis中5分钟
        redisTemplate.opsForValue().set("telephone:" + telephone, code4String,5, TimeUnit.MILLISECONDS);
        return new Result();
    }
}
